#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    pid_t pid = fork();
    if(pid < 0)
    {
        perror("fail to fork");
        return -1;
    }
    else if(pid > 0)
    {
        printf("this is father process\n");
        wait(NULL);
        printf("exec end\n");
    }
    else
    {
        #if 0
        if((execl("/bin/ls","ls","-a",NULL)) == -1)
        {
            perror("fail to execl");
            exit(-1);
        }
        #endif

        #if 0
        if((execlp("ls","ls","-a",NULL)) == -1)
        {
            perror("fail to execlp");
            exit(-1);
        }
        #endif
        #if 0
        char* arr[] = {"ls","-a",NULL};
        if((execv("/bin/ls",arr)) == -1)
        {
            perror("fail to execv");
            exit(-1);
        }
        #endif
        #if 0
        char* arr[] = {"ls","-a",NULL};
        if((execvp("ls",arr)) == -1)
        {
            perror("fail to execvp");
            exit(-1);
        }
        #endif
        #if 0
        if((execl("/home/yyg/vscode_c/test01","./test01",NULL)) == -1)
        {
            perror("fail to execl");
            exit(-1);
        }
        #endif
        #if 0
        if((execl("./test01","./test01",NULL)) == -1)
        {
            perror("fail to execl");
            exit(-1);
        }
        #endif
        #if 1
        if((execl("/home/yyg/myshell/test3.sh","./test3.sh",NULL)) == -1)
        {
            perror("fail to execl");
            exit(-1);
        }
        #endif
        
        //
        printf("hello world\n");
    }
    return 0;
}